$(function() {
	$.post("footballTeampagingList", function(data) {
		if(data.code == 0) {
			let rel = data.data;
			let html = ''
			let html2 = ''
			for(var i in rel) {
				if(i == 0) {
					html += '<li class="active" championNum="' + rel[i].championNum + '" playerValue="' + rel[i].playerValue + '" worldRanking="' + rel[i].worldRanking + '" code="' + rel[i].idPrikey + '">'
					html += '<img src="images/' + rel[i].teamLogo + '" />';
					html += '<p>' + rel[i].teamName + '</p></li>'
				} else if(i < 16) {
					html += '<li championNum="' + rel[i].championNum + '" playerValue="' + rel[i].playerValue + '" worldRanking="' + rel[i].worldRanking + '" code="' + rel[i].idPrikey + '">'
					html += '<img src="images/' + rel[i].teamLogo + '" />';
					html += '<p>' + rel[i].teamName + '</p></li>'
				} else {
					html2 += '<li championNum="' + rel[i].championNum + '" playerValue="' + rel[i].playerValue + '" worldRanking="' + rel[i].worldRanking + '" code="' + rel[i].idPrikey + '">'
					html2 += '<img src="images/' + rel[i].teamLogo + '" />';
					html2 += '<p>' + rel[i].teamName + '</p></li>'
				}
			}
			$(".imgBg").find("img").attr("src", "images/" + rel[0].teamLogo)
			$(".imgBg").find("p").text(rel[0].teamName)
			$(".prize li").each(function() {
				if($(this).attr("class") == "playerValue") {
					$(this).text(rel[0][$(this).attr("class")] + '亿欧元')
				} else {
					$(this).text(rel[0][$(this).attr("class")])
				}

			})
			$(".one").html(html)
			$(".two").html(html2)
		}
	})
	$(".list").delegate('li', 'click', function() {
		$(".list").find("li").removeClass("active")
		$(this).addClass("active")
		$(".championNum").text($(this).attr("championNum"))
		$(".playerValue").text($(this).attr("playerValue") + '亿欧元')
		$(".worldRanking").text($(this).attr("worldRanking"))
		$(".imgBg").find("img").attr("src", $(this).find("img").attr("src"))
		$(".imgBg").find("p").text($(this).find("p").text())
	})
	$.post("selUserDoesExist", function(data) { //判断是否注册
		if(data.code == 0) {
			hb_flag = 1
		} else {
			hb_flag = 0
		}
	})
	$.post("operateTimeAndNumValidated", {
		activityFlag: 1
	}, function(data) {
		if(data.code == 0) {
			hb_time = data.data
			$(".cjcs").text(hb_time)
		} else {
			hb_time = 0
			$(".cjcs").text(hb_time)
		}
	})
	$("#qrxz").click(function() {
		var code = $(".list .active").attr("code")
		if(hb_flag == 1) {
			//调用修改方法
			if(hb_time == 0) {
				$.alert("您得修改次数不足，请分享好友或者朋友圈增加修改机会", "温馨提示");
			} else {
				$.post("addFootballVote", {
					footballTeams: code,
					votingType: 1
				}, function(data) {
					if(data.code == 0) {
						$.toast(data.msg, function() {
							sessionStorage.setItem("hb_type",'1')
							window.location.replace("wx_fx")
						})
					} else {
						$.toast(data.msg, "forbidden");
					}
				})
			}
		} else {
			sessionStorage.setItem("hb_code", code)
			window.location.replace("wx_input?type=1")
		}
	})
	$(".ycjg").click(function(){
		if(hb_flag==0){
			$.toast('请先选择冠军球队进行注册', "forbidden");
		}else{
			sessionStorage.setItem("hb_type",'1')
			window.location.replace("wx_fx")
		}
		
	})
	//选择类型
	$(".nav li").click(function() {
		var url = $(this).attr("url")
		window.location.replace(url)
	})
})
//判断是否注册
var hb_flag = 0
var hb_time = 0